﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.UI;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Documents;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using 纸片人.ConvertClass;
using 纸片人.UtilFolter;

// The Templated Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234235

namespace 纸片人.CalculateControls
{
    public class ProviderDropControl : Control
    {
        Border stateBorder;
        

        #region
        /// <summary>
        /// 获取或设置Type的值
        /// </summary>  
        public object Type
        {
            get { return (object)GetValue(TypeProperty); }
            set { SetValue(TypeProperty, value); }
        }

        /// <summary>
        /// 标识 Type 依赖属性。
        /// </summary>
        public static readonly DependencyProperty TypeProperty =
            DependencyProperty.Register("Type", typeof(object), typeof(ProviderDropControl), new PropertyMetadata("", OnTypeChanged));

        private static void OnTypeChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
        {
            ProviderDropControl target = obj as ProviderDropControl;
            object oldValue = (object)args.OldValue;
            object newValue = (object)args.NewValue;
            if (oldValue != newValue)
                target.OnTypeChanged(oldValue, newValue);
        }

        protected virtual void OnTypeChanged(object oldValue, object newValue)
        {
        }
        #endregion
        public ProviderDropControl()
        {
            this.DefaultStyleKey = typeof(ProviderDropControl);
        }

        protected override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            stateBorder = GetTemplateChild(nameof(stateBorder)) as Border;
            
        }

        /// <summary>
        /// 设置实在连接状态
        /// </summary>
        public void SetConnectState()
        {
            if (stateBorder != null)
            {
                stateBorder.Background = new SolidColorBrush(Colors.Red);  
            }
        }

        /// <summary>
        /// 设置断开连接状态
        /// </summary>
        public void SetDeConnectState()
        {
            stateBorder.Background = null;
            
        }


    }
}
